<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>3-4 到底触发：IntersectionObserver</title>
  <style>
    body {
      margin: 0;
      background: lightseagreen;
      margin-top: 1300px;
    }

    .bottom {
      height: 100px;
      background: lightgreen;
    }
  </style>
</head>

<body>
  <div class="bottom">Lorem ipsum dolor sit amet consectetur adipisicing elit. Ipsum esse saepe obcaecati optio, id,
    voluptatem architecto, harum nesciunt aspernatur corporis vitae. Animi esse quo saepe nulla consectetur, reiciendis
    placeat fugiat!</div>

  <script>
    const divBottom = document.querySelector(".bottom");

    let intersectionObserver = new IntersectionObserver((doms) => {
      const { isIntersecting } = doms[0];
      if (isIntersecting) {
        alert("到底啦，该请求新资源了~~~~");
        // intersectionObserver.unobserve(divBottom);
        // 看业务需求，看用到一次还是多次，记得做完事情取消监听，避免消耗性能
      }
    }, { threshold: [0] });

    intersectionObserver.observe(divBottom);


  </script>
</body>

</html>